﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EFCTP.Entity;
using EFCTP.DBContext;
using EFCTP.IService;

namespace EFCTP.Service
{
    public class ETService : IEFService
    {
        public List<Industry> GetAllIndustries()
        {
            return IndustryContext.db.Industries.ToList();
        }

        public List<Industry> GetIndustryLevelOne()
        {
            //return IndustryContext.db.Industries.Where(s => s.Level == 1).ToList();
            List<Industry> retValue = new List<Industry>();
            retValue.Add(new Industry { Code = "1111", Name = "AAA",Level=1 });
            retValue.Add(new Industry { Code = "2222", Name = "BBBB",Level=1 });
            return retValue;
        }

        public List<Industry> GetIndustryTop(string code)
        {
            return IndustryContext.db.Industries.Where(s => s.ParentCode == code).ToList();
        }

        public List<Product> GetProducts(string code)
        {
            return IndustryContext.db.Industries.Find(code).Products.ToList();
        }

        public Industry GetIndustryByKey(string code)
        {
            return IndustryContext.db.Industries.Find(code);
        }

        public Product GetProductByKey(string code)
        {
            //return IndustryContext.db.Products.Find(code);
            return new Product { Code = "111", Name = "AAA" };
        }
    }
}
